/**********************************************************************
  The MIT License (MIT)
  Copyright (c) 2012 sunriseyuen

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files
  (the "Software"), to deal in the Software without restriction,
  including without limitation the rights to use, copy, modify, merge,
  publish, distribute, sublicense, and/or sell copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be included
  in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
  THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 ***********************************************************************/

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Threading;

using Muki.Framework;
using Muki.Framework.Util;
using Muki.Framework.Business;
using Muki.Entity;
using Muki.UserDefine;

using Dot.StreamObject;

namespace Muki.UserPanel
{
	public class UID03101ABB : BBTask
	{
		public UID03101ABB()
		{
		}

		public override void OnInit()
		{

		}

		public override void Process()
		{

			_Captions.ZZLiveBlock = this.ZZLiveBlock;
			_Captions.DbName      = this.Trans.DbName;

			_Convert.ZZLiveBlock = this.ZZLiveBlock;
			_Convert.Trans       = this.Trans;

			_WXFLite.XDeclareStart();
			//_WXFLite.ZZLiveBlock=this.ZZLiveBlock;


			_WXFLite.Variable("Variables.ZZCOMP_CODE"       , _Captions.Caption("lbl_ZZCOMP_CODE"));
			_WXFLite.Variable("Variables.ZZUID_CODE"        , "UID03101A");
			_WXFLite.Variable("Variables.ZZLOGON_ID"        , this.ZZLOGON_ID);
			_WXFLite.Variable("Variables.ZZDATE_TIME"       , DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
			_WXFLite.Variable("Variables.ZZUID_TITLE"       , _Captions.Caption("lbl_UID03101A"));
			_WXFLite.Variable("Variables.ZZCONTINUE"        , _Captions.Caption("lbl_ZZCONTINUE"));
			_WXFLite.Variable("Variables.ZZFINISH"          , _Captions.Caption("lbl_ZZFINISH"));
			_WXFLite.Variable("Variables.ZZRANGE_FM"        , _Captions.Caption("lbl_ZZRANGE_FM"));
			_WXFLite.Variable("Variables.ZZRANGE_TO"        , _Captions.Caption("lbl_ZZRANGE_TO"));
			_WXFLite.Variable("Variables.ZZPRINT_DATE"      , _Captions.Caption("lbl_ZZPRINT_DATE"));
			_WXFLite.Variable("Variables.ZZPRINT_TIME"      , _Captions.Caption("lbl_ZZPRINT_TIME"));
			_WXFLite.Variable("Variables.DateTime_MinValue" , DateTime.MinValue.ToString("1900-MM-dd"), "datetime");
			_WXFLite.Variable("XCaption.Page_No"            , _Captions.Caption(this.UID_CODE  , "lbl_Page_No"));
			_WXFLite.Variable("ZZAsyncWxfPage"              , "True");

				QueryRows RsUID03101A;

				objZZQLite = new ZZQLite();

				ZZSQLStatement objZZSQLStatement;
				ZZRefx objZZRefx;

				RsUID03101A = new QueryRows(this.Trans);

				objZZSQLStatement             = new ZZSQLStatement();
				objZZSQLStatement.Trans       = this.Trans;
				objZZSQLStatement.ZZLiveBlock = this.ZZLiveBlock;

				objZZRefx           = new ZZRefx();
				objZZRefx.UGET_CODE = "QDD03101A";
				objZZRefx.Trans     = this.Trans;
				objZZRefx.Refx();

				ZZTrace.Debug(ZFILE_NAME, objZZRefx.USQL_CODE);

				objZZSQLStatement.UID_CODE = this.UID_CODE;
				objZZSQLStatement.Process(objZZRefx.USQL_CODE);

				objZZQLite = objZZSQLStatement.oZZQLite;
				objZZQLite.ZZLiveBlock = this.ZZLiveBlock;

				string cAccessName = "";
					foreach (ZZMapping objMapping in objZZRefx.Ref_Mapping)
					{
						cAccessName = "Txt_" + objMapping.ACCESS_TABLE_NAME + "_" + objMapping.ACCESS_COLUMN_NAME;

						_WXFLite.Variable("XWhere."+objMapping.TABLE_NAME+"."+objMapping.COLUMN_NAME,ZZGeneral.XRequest(cAccessName));

						objZZQLite.AddXWhereClause(objMapping.TABLE_NAME, objMapping.COLUMN_NAME,ZZGeneral.XRequest(cAccessName));
					}

				objZZQLite.Make();

				string cSQLString = objZZQLite.SQLStatement;

				ZZTrace.Debug(ZFILE_NAME,cSQLString);


				RsUID03101A.CommandText = cSQLString;
				RsUID03101A.Open();

				_Captions.ZZLiveBlock  =this.ZZLiveBlock;


				foreach(AttributeMapping _AttributeMapping in objZZQLite.AttributeMappings)
				{
					AttributeMapping objaColumn =_AttributeMapping;
					objaColumn.Caption = _Captions.Caption(this.UID_CODE, objaColumn.Caption);

					_WXFLite.XDeclare(objaColumn);
				}


				_WXFLite.XDeclareFinal();


				while (!RsUID03101A.EOF)
				{
					_WXFLite.AddNew();
					int i=0;
					foreach(AttributeMapping _AttributeMapping in objZZQLite.AttributeMappings)
					{
						_WXFLite[_AttributeMapping.Name]  = RsUID03101A[i];
						i++;
					}


					_WXFLite.Update();

					RsUID03101A.MoveNext();
				}

				ZZTrace.Debug(ZFILE_NAME, "==**==");
		}

#region Field

		const string ZFILE_NAME = "UID03101ABB";
		private ZZQLite  objZZQLite;
		private ZZDataPermission _DataPermission = new ZZDataPermission();
		private string   _FileName               = "UID03101A";
		private XConvert   _Convert              = new XConvert();
		private Wxf _WXFLite                     = new Wxf();
		private ZZCaptions   _Captions           = new ZZCaptions();

#endregion

#region Properties

		public Wxf WXFLite     { get { return _WXFLite;  } set { _WXFLite = value;  }  }
		public string FileName { get { return _FileName; } set { _FileName = value; }  }

#endregion
	}
}
